#!/bin/bash
################################
#RabbitMQ Cluster群集安装配置

#controller1节点
#拷贝到其它节点，统一认证的Erlang Cookie
scp /var/lib/rabbitmq/.erlang.cookie controller2:/var/lib/rabbitmq/
scp /var/lib/rabbitmq/.erlang.cookie controller3:/var/lib/rabbitmq/

#rabbitmqctl status
#使用Disk模式
systemctl stop rabbitmq-server
pkill beam.smp
rabbitmqctl stop
rabbitmq-server -detached 
rabbitmqctl cluster_status #查看状态

read -p "请在controller2、controller3执行 2.controller2,3.sh，执行完成后按<ENTER>继续..." 
#任意一个节点上执行
rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'  #设置镜像队列
rabbitmqctl set_cluster_name RabbitMQ-Cluster #更改群集名称
rabbitmqctl cluster_status #查看群集状态

# 节点从集群中退出
# rabbitmqctl forget_cluster_node rabbit@server2